<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.sdry.model.zc.ZcSysUserEntity" %>
<% 
	ZcSysUserEntity zcSysUserEntity =  (ZcSysUserEntity)request.getSession().getAttribute("user");
	//String roleId = zcSysUserEntity.getRoleId(); 
	//String roleIds[] = roleId.split(",");
	String roleName = zcSysUserEntity.getRoleName(); 
	String roleNames[] = roleName.split(",");
	boolean isAdmin= false;
	/* for(int i =0;i<roleIds.length;i++){
		if("2".equals(roleIds[i])){
			isAdmin = true;
		}
	} */
	for(int i =0;i<roleNames.length;i++){
		if("管理员".equals(roleNames[i])|| "超级管理员".equals(roleNames[i])){
			isAdmin = true;
		}
	}
	
	int istrue = 0;
	for(int i =0;i<roleNames.length;i++){
		if("管理员".equals(roleNames[i])|| "超级管理员".equals(roleNames[i]) || "库管".equals(roleNames[i]) || "班长".equals(roleNames[i])){
			istrue = 1;
		}
	}
%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>精简库存</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
	<link rel="stylesheet" type="text/css" href="https://www.huangwx.cn/css/sweetalert.css">
<script type="text/javascript" src="https://www.huangwx.cn/js/sweetalert-dev.js"></script>
	<style type="text/css">
		.layui-table-view .layui-table-body tr.table_tr_click {
	      background-color: pink;
	    }
	</style>
</head>
<body class="layui-anim layui-anim-up">
	<div class="x-nav">
		<span class="layui-breadcrumb">
  			<a href="">首页</a>
			<a>
				<cite>精简库存</cite>
			</a>
		</span>
    </div>
	<div class="x-body">
		<div class="layui-row" style="margin-bottom: 10px">
			<div class="layui-form">
				<div class="layui-input-inline">
					<div class="layui-input-inline" style="width: 190px">
						<select class="" name="keyword" id="keyword" lay-filter="keyword">
							<option value="">请选择供应商</option>
							<c:forEach items="${allCustomerList }" var="customer">
								<option value="${customer.id}">${customer.customer_name }</option>
							</c:forEach>
						</select>
					</div>
					<div class="layui-input-inline" style="width: 150px">
						<input class="layui-input" id="keyword2" placeholder="请输入SAP/QAD查询" style="width: 150px">
					</div>
				</div>
				<button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
			 <button class="layui-btn layui-btn-danger" id="export"><i class="layui-icon layui-icon-upload"></i>导出</button> </div>
		</div>
		<xblock>
	        <button class="layui-btn layui-btn-warm" id="typeZhuanHuan"><i class="layui-icon layui-icon-add-circle-fine"></i>良品转不良品</button>
	        <button class="layui-btn layui-btn-warm" id="typeZhuanHuan1"><i class="layui-icon layui-icon-add-circle-fine"></i>不良品转良品</button>
	    </xblock>
		<div id = "fDiv">
			<table class="layui-hide" id="inventoryInfoOnlyCountList" lay-filter="inventoryInfoOnlyCountList"></table>
		</div>
	</div>
	
	<div id="typeZhuanHuanDivID" hidden="hidden">
		<form class="layui-form" id="typeZhuanHuanFormID">
			<br>
				<label class="layui-form-label">物料名称</label>
				<input class="layui-input" id="materiel_name" style="width: 300px;" readonly>
				<!-- 物料id -->
				<input type="hidden" id="mid" name="mid">
				<!-- 物料批次 -->
				<input type="hidden" id="mBatch" name="mBatch">
				<!-- 良品数量 -->
				<input type="hidden" id="mNum" name="mNum">
				<!-- 不良品数量 -->
				<input type="hidden" id="mNumRejects" name="mNumRejects">
			<br>
				<label class="layui-form-label">SAP/QAD</label>
				<input class="layui-input" id="materiel_num" style="width: 300px;" readonly>
			<br>
				<label class="layui-form-label">转换类型</label>
				<div  class="layui-input-inline" style="width: 300px; float: left">
					<select class="layui-input" id="type" name="type" lay-verify="required">
						<option value="0">不良品转良品</option>
						<option value="1">良品转不良品</option>
					</select>
				</div>
				<div style="margin-top: 10px;margin-right: -20px;">
                    <span style="color:red; font-size: 24px; margin-left: 4px">*</span>
                </div>
				<!-- <span class="xing"></span> -->
			<br>
			<br>
				<label class="layui-form-label">转换数量</label>
				<input class="layui-input" id="zhNum" name="zhNum" lay-verify="zhNum" style="width: 300px;display:inline;">
				<div class="layui-inline" style="margin-top: 8px;">
                    <span style="color:red; font-size: 24px; margin-left: -1px">*</span>
                </div>
				<!-- <span class="xing"></span> -->
			<br>
			<br>
				<label class="layui-form-label">转换原因</label>
				<input class="layui-input" id="zhreason" name="zhreason"  style="width: 300px;display:inline;">
			<br>
			<br>
			<label class="layui-form-label">上传图片</label>
			<button type="button" class="layui-btn" id="file" name="file" >
				<i class="layui-icon">&#xe67c;</i>上传图片
			</button>
			<input type="hidden" id="img_url" name="img_url">
			<!-- 
			<div class="layui-input-inline uploadHeadImage"style="margin-left:40px;" >
	            <div class="layui-upload-drag" id="headImg">
		            <i class="layui-icon"></i>
		            <p>点击上传图片，或将图片拖拽到此处</p>
	            </div>
            </div>
            <div class="layui-input-inline">
	            <div class="layui-upload-list">
		            <img class="layui-upload-img headImage" src="" style="width:140px;height:140px" id="demo1">
		            <p id="demoText"></p>
	            </div>
            </div> 
            -->
            <br>
			<br>
			<button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="typeZhuanHuanForm" style="margin-left:140px;">立即提交</button>
			&emsp;&emsp;&emsp;&emsp;
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</form>
    </div>
    <!-- <script type="text/javascript">
	    layui.use(["jquery", "upload", "form", "layer", "element"], function () {
	        var $ = layui.$,
	            element = layui.element,
	            layer = layui.layer,
	            upload = layui.upload,
	            form = layui.form;
	        //拖拽上传
	        var uploadInst = upload.render({
	            elem: '#headImg'
	            , url:'${pageContext.request.contextPath }/upload/picUpload.do'
	            , size: 500
	            , before: function (obj) {
	                //预读本地文件示例，不支持ie8
	                obj.preview(function (index, file, result) {
	                    $('#demo1').attr('src', result); //图片链接（base64）
	                });
	            }
	            , done: function (res) {
	                //如果上传失败
	                if (res.code > 0) {
	                    return layer.msg('上传失败');
	                }
	                //上传成功
	                //打印后台传回的地址: 把地址放入一个隐藏的input中, 和表单一起提交到后台, 此处略..
	                //console.log(res.data.src);
	                //window.parent.uploadHeadImage(res.data.src);
	                console.log(res.data.src)
	                $('#img_url').val(res.data.src)
	                var demoText = $('#demoText');
	                demoText.html('<span style="color: red;">上传成功!!!</span>');
	            }
	            , error: function () {
	                //演示失败状态，并实现重传
	                var demoText = $('#demoText');
	                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
	                demoText.find('.demo-reload').on('click', function () {
	                    uploadInst.upload();
	                });
	            }
	        });
	        element.init();
	    });
	</script> -->
	<script type="text/javascript">
		//日期格式转换
		function date2String(timestamp){
			var d = new Date(timestamp);
			var date = (d.getFullYear()) + "-" + 
		       (d.getMonth() + 1<10?"0"+(d.getMonth() + 1):d.getMonth() + 1) + "-" +
		       (d.getDate()<10?"0"+d.getDate():d.getDate());
			return date;
		}
		layui.use(['table','layer','upload','form','laydate'], function(){
			var table = layui.table;
			var layer = layui.layer;
			var form = layui.form;
			var laydate = layui.laydate;
			var upload = layui.upload;
			
			//**********图片上传**********
		    upload.render({
		    	elem: '#file'
		      	,url: '${pageContext.request.contextPath}/upload/picUpload.do'
		      	,multiple: false
			    //允许上传的文件类型
			    ,exts: 'jpg|png|gif|jpeg|PNG|JPG|'
			    ,done: function(res){
				    //上传完毕
				   	if(res != "" && res != null){
				    	toastrStyle();
				    	toastr.success('文件上传成功！');
						$("#img_url").val(res);
					} else {
						toastrStyle();
						toastr.warning('图片上传失败！');
					}
				}
		    });
			
			var currentBtn = document.getElementById('typeZhuanHuan1');
			var istrue = '<%=istrue%>'
			if(istrue == 0){
				currentBtn.style.display = "none";
			}
			
			/* var $ = layui.jquery, active = {
				reload:function () {
					var keyword = $("#keyword").val();
					var keyword2 = $("#keyword2").val();
					//keyword2 = "'"+keyword2+"'";
					var strWhere = "";
					if(keyword!="" && keyword2 != "''"){
						strWhere = "m.customer_id = "+keyword+"and m.materiel_num like '%"+keyword2+"%' and ";
					}else if(keyword!="" && keyword2 == "''"){
						strWhere = "m.customer_id = "+keyword+" and ";
					}else if(keyword=="" && keyword2 != "''"){
						strWhere = "m.materiel_num like '%"+keyword2+"%' and ";
					}else{
						strWhere = ' ';
					}
					table.reload('contenttable',{
						method:'get',
						where:{"strWhere":strWhere}
						,page: {
		                    curr: 1//重新从第 1 页开始
		                }
					});
				}
			} */
			
			/* llm 19.12.13 修改 */
			var $ = layui.jquery, active = {
				reload:function () {
					var keyword = $("#keyword").val();
					var keyword2 = $("#keyword2").val();
					
					table.reload('contenttable',{
						method:'get',
						where:{"customer_id":keyword, "materiel_num":keyword2}
						,page: {
		                    curr: 1//重新从第 1 页开始
		                }
					});
				}
			}
			
			/* var keyword = $("#keyword").val();
			var keyword2 = $("#keyword2").val();
			//keyword2 = "'"+keyword2+"'";
			var strWhere = "";
			if(keyword!="" && keyword2 != "''"){
				strWhere = "m.customer_id = "+keyword+"and m.materiel_num like '%"+keyword2+"%' and ";
			}else if(keyword!="" && keyword2 == "''"){
				strWhere = "m.customer_id = "+keyword+" and ";
			}else if(keyword=="" && keyword2 != "''"){
				strWhere = "m.materiel_num like '%"+keyword2+"%' and ";
			}else{
				strWhere = ' ';
			} */
			
			
			$('.layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			table.render({
				elem: '#inventoryInfoOnlyCountList'
				//,url:'${pageContext.request.contextPath }/inventoryManagement/selectInventoryInfoOnlyCountList.do'
				,url:'${pageContext.request.contextPath }/inventoryManagement/selectInventoryInfoOnlyCountListFromLian.do'
				,title: '库存列表'
				,id :'contenttable'
				,toolbar: '#toolbarDemo'
				//,where:{"strWhere":strWhere}
				,limits:[10,20,30]
				,request: {
                    pageName: 'page',
                    limitName: 'pageSize'
                }
				,cols: [[
					{type: 'checkbox', fixed: 'left'}
					,{field:'', title:'序号', sort: true, type:'numbers', width: 60}
					,{field:'customer', title:'供应商',templet:function(row){
						if(row.materiel.customer!=null){
							return row.materiel.customer.customer_name;
						}else{
							return "";
						}
					}}
					,{field:'materiel_name', title:'物料名称',templet:function(row){
						if(row.materiel!=null){
							return row.materiel.materiel_name;
						}else{
							return "";
						}
					}}
					,{field:'materiel_num', title:'SAP/QAD',templet:function(row){
						if(row.materiel!=null){
							return row.materiel.materiel_num;
						}else{
							return "";
						}
					}}
					,{field:'mBatch', title:'批次', align: 'center'}
					,{field:'mNum', title:'良品数量'}
					,{field:'mNumRejects', title:'不良品数量'}
					,{field:'mNumProfitAndLoss', title:'损溢',edit:true,templet: function (row){
						return '<span style="color: blue">'+row.mNumProfitAndLoss+'</span>';
					}}
					,{field:'countAll', title:'良品总库存'}
					,{field:'countAllRejects', title:'不良品总库存',width: 160}
					,{field:'', title:'总库存',templet:function(row){
						return row.countAll + row.countAllRejects;
					}}
					/* ,{field:'unit', title:'单位',templet:function(row){
						if(row.materiel!=null){
							return row.materiel.unit;
						}else{
							return "";
						}
					}}
					,{field:'enterDate', title:'入库日期',templet:function(d)
						{
							return changeDateFormat(d.enterDate)
						}
					}
					,{field:'userName', title:'入库人',templet:function(row){
						if(row.zcSysUser!=null){
							return row.zcSysUser.userName;
						}else{
							return "";
						}
					}} ,{field:'reason', title:'转换原因'
					},{field:'img_url', title:'上传图片',templet:function(row){
						if (row.img_url == "" || row.img_url == null) {
							return "";
						}
							return "<a href='${pageContext.request.contextPath}/inventoryManagement/upDownlodeFile.do?down="+row.img_url+"'>图片</a>";
						}} */
				]]
				,page: true
				,done:function(res, curr, count){
	               // merge(res);
					$('th').css({
	                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
	                })
				}
			});
			//"出库单详细"的行内编辑事件
            table.on('edit(inventoryInfoOnlyCountList)', function(obj){
                var fieldValue = obj.value, 	//得到修改后的值
                    rowData = obj.data, 		//得到所在行所有键值
                    fieldName = obj.field; 		//得到字段
                    max = rowData.small_num;
               	var firstValue = $(this).prev().text(); 	//得到修改前的值
               	var patrn = /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/;
               	if(!patrn.test(fieldValue)){
               		toastr.warning("只能是数字！");
               		//$(this)[0].value = $(this).prev().text(); //还原值
               		setTimeout(function(){
                        location.reload();
                    },1000);
               	} else {
               		var url = '${pageContext.request.contextPath}/InventoryInfoOnlyCountRejects/profitAndLoss.do';
	               	//保存修改出库单详细表的值    
                    layui.use('jquery',function(){
                        var $ = layui.$;
                        $.ajax({
                            type: "post",
                            url: url,
                            data: {mid:rowData.mid,mbatch:rowData.mBatch, mnum:fieldValue,enterdate:rowData.enterDate,enterperson:rowData.enterPerson},
                            success: function(zcInventoryInfoId){
                                if(zcInventoryInfoId > 0){
                                    toastrStyle();
                                    toastr.success("修改成功！");
                                    /* setTimeout(function(){
                                        location.reload();
                                    },1000); */
                                }else{
                                    toastrStyle();
                                    toastr.warning("修改失败！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }
                            }
                        });
                    });
               	}
            });
			//监听复选框事件
			table.on('checkbox(inventoryInfoList)',function(obj){
				if(obj.checked == true && obj.type == 'all'){ 
					//点击全选 
					$('.layui-table-body table.layui-table tbody tr').addClass('layui-table-click'); 
				}else if(obj.checked == false && obj.type == 'all'){ 
					//点击全不选 
					$('.layui-table-body table.layui-table tbody tr').removeClass('layui-table-click'); 
				}else if(obj.checked == true && obj.type == 'one'){ 
					//点击单行
					if(obj.checked == true){ 
						obj.tr.addClass('layui-table-click'); 
					}else{ 
						obj.tr.removeClass('layui-table-click'); 
					} 
				}else if(obj.checked == false && obj.type == 'one'){ 
					//点击全选之后点击单行 
					if(obj.tr.hasClass('layui-table-click')){
						obj.tr.removeClass('layui-table-click'); 
					} 
				}
			})
			/**
	         * 新增--提交
	         */
	        form.on('submit(typeZhuanHuanForm)', function (data) {
	        	$("#type").removeAttr("disabled"); 
	            
                var fromdata = $("#typeZhuanHuanFormID").serialize();
             var title = "类型转换"
                var url = '${pageContext.request.contextPath}/InventoryInfoOnlyCountRejects/typeZhuanHuan.do';
                //添加配货单
                $.ajax({
                    url : url,
                    data: fromdata,
                    cache : false,
                    async: false,
                    type : "post",
                }).done(
                    function(res) {
                        if (res > 0) {
                            toastr.success(title+'成功');
                            setTimeout(function(){
                                window.location.reload();
                                $("#reset").click();
                            },1000);
                        }else if(res == -1){
                        	toastr.success("库存数量不足"+title+'失败');
                            setTimeout(function(){
                                window.location.reload();
                                $("#reset").click();
                            },1000);
                        }else{
                            toastr.error(title+'失败！');
                            setTimeout(function(){
                                location.reload();
                            },1000);
                        }
                    }
                ).fail(
                    function(res) {
                        toastr.error(title+'失败！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                )
                return false;
                
	        });
			
			
			/**
			 * 新增表单校验
			 */
			form.verify({
				//value：表单的值、item：表单的DOM对象
	            required: function(value, item){
	            	value = $.trim(value)
	            	if(value == '' || value == null){
	                    return '不能为空';
	                }
	            },
	          	//value：表单的值、item：表单的DOM对象
	            zhNum: function(value, item){
	            	var value = $.trim(value)
	            	var mNum = $.trim($("#mNum").val())
	            	var mNumRejects = $.trim($("#mNumRejects").val())
	            	var type = $.trim($("#type").val())
	            	var re = /^[1-9]\d*$/;
	            	if(value != '' && value != null && !re.test(value)){
	                    return '请输入大于0的正整数';
	                }else if(type == 0 && parseInt(mNumRejects) < parseInt(value)){
		                return '转换数量不能大于库存数量';
	                }else if(type == 1 && parseInt(mNum) < parseInt(value)){
		                return '转换数量不能大于库存数量';
	                } else if(value == '' || value == null){
	                	return '请输入转换数量';
	                }
	            },
			});

			
			
			//增加
	        $("#typeZhuanHuan").click(function(){
	        	var checkStatus = table.checkStatus('contenttable')
	            var datas = checkStatus.data;
	        	if(datas.length != 1){
	                toastr.warning("请选择一条记录！");
                }else{
		            var data = datas[0];
		            layer.open({
		                type: 1 					//Page层类型
		                ,area: ['560px', '580px'] 	//宽  高
		                ,title: '类型转换'
		                ,shade: 0.6 				//遮罩透明度
		                ,maxmin: true 				//允许全屏最小化
		                ,anim: 1 					//0-6的动画形式，-1不开启
		                ,content: $('#typeZhuanHuanDivID')
		                ,end: function () {
		                    var formDiv = document.getElementById('typeZhuanHuanDivID');
		                    formDiv.style.display = '';
		                }
		                ,success: function(){
		                	$("#materiel_name").val(data.materiel.materiel_name);
		                    $("#materiel_num").val(data.materiel.materiel_num);
		                    $("#mid").val(data.mid);
		                    $("#mNum").val(data.mNum);
		                    $("#mNumRejects").val(data.mNumRejects);
		                    $("#mBatch").val(data.mBatch);
		                    $("#zhNum").val("");
		                    $("#zhNum").select();
		                    $("#type").val(1);
		                    $("#type").attr("disabled","disabled");
		                    form.render();
		                }
		            });
                }
	        });
	        $("#export").click(function(){
	        	var keyword = $("#keyword").val();
				var keyword2 = $("#keyword2").val();
				//keyword2 = "'"+keyword2+"'";
				var strWhere = "";
				if(keyword!="" && keyword2 != "''"){
					strWhere = "m.customer_id = "+keyword+"and m.materiel_num like '%"+keyword2+"%' and ";
				}else if(keyword!="" && keyword2 == "''"){
					strWhere = "m.customer_id = "+keyword+" and ";
				}else if(keyword=="" && keyword2 != "''"){
					strWhere = "m.materiel_num like '%"+keyword2+"%' and ";
				}else{
					strWhere = ' ';
				}
				    //window.location.href='${pageContext.request.contextPath}/inventoryManagement/doExportallonly.do?strWhere='+strWhere;
				//var url = "${pageContext.request.contextPath}/inventoryManagement/doExportallonly.do"
				var url = "${pageContext.request.contextPath}/inventoryManagement/doExportallonlyFromLian.do"
				var $form=$(document.createElement('form')).css({'display':'none'}).attr("method","POST").attr("action",url);
			    var $input=$(document.createElement('input')).attr('type','hidden').attr('name','strWhere').val(strWhere);
			    $form.append($input);
			    $("body").append($form);
			    $form.submit();    
	        })
			//增加
	        $("#typeZhuanHuan1").click(function(){
	        	var checkStatus = table.checkStatus('contenttable')
	            var datas = checkStatus.data;
	        	if(datas.length != 1){
	                toastr.warning("请选择一条记录！");
                }else{
		            var data = datas[0];
		            layer.open({
		                type: 1 					//Page层类型
		                ,area: ['500px', '420px'] 	//宽  高
		                ,title: '类型转换'
		                ,shade: 0.6 				//遮罩透明度
		                ,maxmin: true 				//允许全屏最小化
		                ,anim: 1 					//0-6的动画形式，-1不开启
		                ,content: $('#typeZhuanHuanDivID')
		                ,end: function () {
		                    var formDiv = document.getElementById('typeZhuanHuanDivID');
		                    formDiv.style.display = '';
		                }
		                ,success: function(){
		                	$("#materiel_name").val(data.materiel.materiel_name);
		                    $("#materiel_num").val(data.materiel.materiel_num);
		                    $("#mid").val(data.mid);
		                    $("#mNum").val(data.mNum);
		                    $("#mNumRejects").val(data.mNumRejects);
		                    $("#mBatch").val(data.mBatch);
		                    $("#zhNum").val("");
		                    $("#zhNum").select();
		                    $("#type").val(0);
		                    $("#type").attr("disabled","disabled");
		                    form.render();
		                }
		            });
                }
	        });
			
			
		})
		 function changeDateFormat(timestamp) {
    	if (timestamp == '') {
			return '';
		} else {
			var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
			Y = date.getFullYear() + '-';
			M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
			D = (date.getDate()+1 < 10 ? '0'+(date.getDate()) : date.getDate())+ '      ';
			H = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours())+ ':';
            MI= (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes())+':';
            S = (date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds());
				
				return Y+M+D+H+MI+S;
		
		}
		}
		//合并单元格
		function merge(res) {
	        var data = res.data;
	        var mergeIndex = 0;//定位需要添加合并属性的行数
	        var mergeIndexAll = 0;//定位需要添加合并属性的行数
	        var mergeIndexSize = 0;//定位需要添加合并属性的行数
	        var mark = 1; //这里涉及到简单的运算，mark是计算每次需要合并的格子数
	        var columsName = ['customer_id'];//需要合并的列名称
	        var columsNameAll = ['materiel_name','materiel_num','countAll','unit'];//需要合并的列名称
	        var columsNameSize = ['materiel_size','materiel_properties'];//需要合并的列名称
	        var columsIndex = [2];//需要合并的列索引值
	        var columsIndexAll = [3,4,7,8];//需要合并的列索引值
	        var columsIndexSize = [5,6];//需要合并的列索引值
	    	var allMark = 1;
	    	var sizeMark = 1;
	        for (var k = 0; k < columsNameAll.length; k++) { //这里循环所有要合并的列
	            var trArr = $("#fDiv .layui-table-body>.layui-table").find("tr");//所有行
	                for (var i = 1; i < res.data.length; i++) { //这里循环表格当前的数据
	                    var tdCurArr = trArr.eq(i).find("td").eq(columsIndexAll[k]);//获取当前行的当前列
	                    var tdPreArr = trArr.eq(mergeIndexAll).find("td").eq(columsIndexAll[k]);//获取相同列的第一列
	                    if(data[i].materiel.materiel_num === data[i-1].materiel.materiel_num){
	                    	allMark+=1;
	                    	tdPreArr.each(function () {//相同列的第一列增加rowspan属性
	                            $(this).attr("rowspan", allMark);
	                        });
	                        tdCurArr.each(function () {//当前行隐藏
	                            $(this).css("display", "none");
	                        });
	                    }else{
	                    	mergeIndexAll = i;
	                    	allMark=1;
	                    }
	                }
	            mergeIndexAll = 0;
	            allMark = 1;
	        } 
	        for (var k = 0; k < columsName.length; k++) { //这里循环所有要合并的列
	            var trArr = $("#fDiv .layui-table-body>.layui-table").find("tr");//所有行
	                for (var i =   1; i < res.data.length; i++) { //这里循环表格当前的数据
	                    var tdCurArr = trArr.eq(i).find("td").eq(columsIndex[k]);//获取当前行的当前列
	                    var tdPreArr = trArr.eq(mergeIndex).find("td").eq(columsIndex[k]);//获取相同列的第一列
	                    if (data[i].materiel[columsName[k]] === data[i-1].materiel[columsName[k]]) { //后一行的值与前一行的值做比较，相同就需要合并
	                        mark += 1;
	                        tdPreArr.each(function () {//相同列的第一列增加rowspan属性
	                            $(this).attr("rowspan", mark);
	                        });
	                        tdCurArr.each(function () {//当前行隐藏
	                            $(this).css("display", "none");
	                        });
	                    }else {
	                        mergeIndex = i;
	                        mark = 1;//一旦前后两行的值不一样了，那么需要合并的格子数mark就需要重新计算
	                    }
	                }
	            mergeIndex = 0;
	            mark = 1;
	        } 
	    }
		function formatcfile(val,row){
			if (val == "" || val == null) {
				return "";
			}
			return "<a href='${pageContext.request.contextPath}/InventoryInfoOnlyCountRejects/upDownlodeFile.do?down="+val+"'>图片</a>";
		}
		function mergeDetails(res) {
	        var data = res.data;
	        var mergeIndex = 0;//定位需要添加合并属性的行数
	        var mark = 1; //这里涉及到简单的运算，mark是计算每次需要合并的格子数
	        var columsName = ['region_name','location_code'];//需要合并的列名称
	        var columsIndex = [2,4];//需要合并的列索引值
	        for (var k = 0; k < columsName.length; k++) { //这里循环所有要合并的列
	            var trArr = $("#details .layui-table-body>.layui-table").find("tr");//所有行
	            //console.log(trArr)
	                for (var i = 1; i < res.data.length; i++) { //这里循环表格当前的数据
	                    var tdCurArr = trArr.eq(i).find("td").eq(columsIndex[k]);//获取当前行的当前列
	                    var tdPreArr = trArr.eq(mergeIndex).find("td").eq(columsIndex[k]);//获取相同列的第一列
	                    if (data[i].zcTrayAndLocation[columsName[k]] === data[i-1].zcTrayAndLocation[columsName[k]]) { //后一行的值与前一行的值做比较，相同就需要合并
	                        mark += 1;
	                        tdPreArr.each(function () {//相同列的第一列增加rowspan属性
	                            $(this).attr("rowspan", mark);
	                        });
	                        tdCurArr.each(function () {//当前行隐藏
	                            $(this).css("display", "none");
	                        });
	                    }else {
	                        mergeIndex = i;
	                        mark = 1;//一旦前后两行的值不一样了，那么需要合并的格子数mark就需要重新计算
	                    }
	                }
	            mergeIndex = 0;
	            mark = 1;
	        }
	    }
		$(document).on('click', '#fDiv .layui-table-view .layui-table-body tr', function (event) {
	    	var trElem = $(this);
	      	var tableView = trElem.closest('.layui-table-view');
	      	tableView.find('.layui-table-body tr.table_tr_click').removeClass('table_tr_click');
	      	tableView.find('.layui-table-body tr[data-index="' + trElem.data('index') + '"]').addClass('table_tr_click');
	    });
		toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
	</script>
</body>
</html>
